package com.health.mapp.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.health.db.model.GoodsOrderExample;
import com.health.db.service.sm.IGoodsOrderService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QueryUserEntityGoodsListReq;
import com.health.mapp.bean.QueryUserEntityGoodsListResp;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 *  订购商品查询类
 * @author YuChong
 *
 */
public class QueryUserEntityGoodsListImpl implements ActionInterface {

	 @Autowired	
	 private IGoodsOrderService goodsOrderService;
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		QueryUserEntityGoodsListReq req=(QueryUserEntityGoodsListReq) reqBean;
		QueryUserEntityGoodsListResp _resp= new QueryUserEntityGoodsListResp();
		
		GoodsOrderExample temp = new GoodsOrderExample();
		
		Integer pageNo=req.getPageNo();
		Integer pageSize=req.getPageNum();
		
		if(null!=pageNo&&null!=pageSize){
			temp.setOffset((pageNo.intValue()-1)*pageSize.intValue());
			temp.setPageSize(pageSize.intValue());
			_resp.setPageNo(pageNo);
			_resp.setPageNum(pageSize);
		}
		
		//用户编号
		 String userId = req.getUserId();
		 
		 String goodsType = req.getGoodsType();
		 
		 
		 if (StringUtils.isNotBlank(userId)&&StringUtils.isNotBlank(goodsType)) {
			 
			 temp.setOwnerid(Long.valueOf(userId));
			 temp.setGoodsType(goodsType);
			 _resp.setCourseList(goodsOrderService.selectByUserIdAndType(temp));
			 
			
		}else{
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return _resp;
		}
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
 
		return _resp;
	}

	public IGoodsOrderService getGoodsOrderService() {
		return goodsOrderService;
	}

	public void setGoodsOrderService(IGoodsOrderService goodsOrderService) {
		this.goodsOrderService = goodsOrderService;
	}


}
